/*
 * @Description:
 * @Date: 2024-02-25 20:49:38
 * @LastEditTime: 2024-03-03 14:02:50
 * @FilePath: /pure-admin-thin/src/api/user.ts
 */
import { http } from "@/utils/http";
import { any, object } from "vue-types";

export type LoginResult = {
  code: number;
  success: boolean;
  data: {
    token: string;
  };
};

export type UserResult = {
  code: number;
  success: boolean;
  data: {
    [x: string]: any;
    /** 用户名 */
    username: string;
    /** 当前登陆用户的角色 */
    roles: Array<string>;
    /** `token` */
    access_token: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

export type RefreshTokenResult = {
  success: boolean;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

/** 登录 */
export const getLogin = (data?: object) => {
  return http.request<UserResult>("post", "/login", { data });
};

/** 刷新token */
export const refreshTokenApi = (data?: object) => {
  return http.request<RefreshTokenResult>("post", "/refreshToken", { data });
};

// 用户列表
export const getUserList = (data?: object) => {
  return http.request<UserResult>("post", "/user_list", { data });
};

// group / history_message
export const getGroupMessages = (data?: object) => {
  return http.request<UserResult>("post", "/group/history_message", { data });
};

export const getExposures = (data?: object) => {
  return http.request<UserResult>("post", "/exposure_list", { data });
};

export const delMsg = (msg_id: string) => {
  return http.request("delete", `/message/${msg_id}`, {});
};

export const delExposure = (msg_id: string) => {
  return http.request("delete", `/exposure/${msg_id}`, {});
};

export const loadDashboard = () => {
  return http.request("get", `/dashboard`, {});
};

export const loadGroups = () => {
  return http.request("get", `/groups`, {});
};

export const sendPrivateMsg = (data: any) => {
  return http.request("post", `/post_private_message`, { data });
};

export const sendGroupMsg = (data: any) => {
  return http.request("post", `/post_group_message`, { data });
};

export const sendGroupAd = (data: any) => {
  return http.request<UserResult>("post", `/send_group_ad`, { data });
};

export const loadEntityTypes = () => {
  return http.request("get", `/entity_types`, {});
};

export const loadSBCategory = () => {
  return http.request("get", `/sb_category`, {});
};
